package org.whz;

import org.junit.jupiter.api.Test;
import org.whz.entity.*;
import org.whz.factory.CommodityFactory;
import org.whz.service.SellService;
import org.whz.service.impl.SellServiceImpl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * 测试程序
 */
public class TestApp {


    @Test
    public  void  test_1(){
        Apple apple = CommodityFactory.create(Apple.class);
        apple.setName("苹果");
        apple.setPrice(new BigDecimal("8.00"));

        Strawberry strawberry = CommodityFactory.create(Strawberry.class);
        strawberry.setName("草莓");
        strawberry.setPrice(new BigDecimal("13.00"));

        //购买
        List<Detail> detailList = new ArrayList<>();

        Detail appleDetail = new Detail(apple, 2);
        Detail strawberryDetail = new Detail(strawberry,2);

        detailList.add(appleDetail);
        detailList.add(strawberryDetail);

        //收款
        SellService sellService = new SellServiceImpl();
        try {
            BigDecimal  amount = sellService.collectAmount(detailList);
            System.out.println("合计收款：" + amount);
        }catch (Exception e){
            System.out.println("收钱程序异常");
        }
    }

    @Test
    public  void  test_2(){
        Apple apple = CommodityFactory.create(Apple.class);
        apple.setName("苹果");
        apple.setPrice(new BigDecimal("8.00"));

        Strawberry strawberry = CommodityFactory.create(Strawberry.class);
        strawberry.setName("草莓");
        strawberry.setPrice(new BigDecimal("13.00"));

        Mango mango = CommodityFactory.create(Mango.class);
        mango.setName("芒果");
        mango.setPrice(new BigDecimal("20"));

        //购买
        List<Detail> detailList = new ArrayList<>();

        Detail appleDetail = new Detail(apple, 2);
        Detail strawberryDetail = new Detail(strawberry,2);
        Detail mangoDetail = new Detail(mango, 10);

        detailList.add(appleDetail);
        detailList.add(strawberryDetail);
        detailList.add(mangoDetail);

        SellService sellService = new SellServiceImpl();
        try {
            BigDecimal  amount = sellService.collectAmount(detailList);
            System.out.println("合计收款：" + amount);
        }catch (Exception e){
            System.out.println("收钱程序异常");
        }
    }

    @Test
    public  void  test_3(){
        Apple apple = CommodityFactory.create(Apple.class);
        apple.setName("苹果");
        apple.setPrice(new BigDecimal("8.00"));

        Strawberry strawberry = CommodityFactory.create(Strawberry.class);
        strawberry.setName("草莓");
        strawberry.setPrice(new BigDecimal("13.00"));
        strawberry.setDiscount(new BigDecimal("0.8"));

        Mango mango = CommodityFactory.create(Mango.class);
        mango.setName("芒果");
        mango.setPrice(new BigDecimal("20"));

        //购买
        List<Detail> detailList = new ArrayList<>();

        Detail appleDetail = new Detail(apple, 2);
        Detail strawberryDetail = new Detail(strawberry,2);
        Detail mangoDetail = new Detail(mango, 10);

        detailList.add(appleDetail);
        detailList.add(strawberryDetail);
        detailList.add(mangoDetail);

        SellService sellService = new SellServiceImpl();
        try {
            BigDecimal  amount = sellService.collectAmount(detailList);
            System.out.println("合计收款：" + amount);
        }catch (Exception e){
            System.out.println("收钱程序异常");
        }
    }

    @Test
    public  void  test_4(){
        Apple apple = CommodityFactory.create(Apple.class);
        apple.setName("苹果");
        apple.setPrice(new BigDecimal("8.00"));

        Strawberry strawberry = CommodityFactory.create(Strawberry.class);
        strawberry.setName("草莓");
        strawberry.setPrice(new BigDecimal("13.00"));
        strawberry.setDiscount(new BigDecimal("0.8"));

        Mango mango = CommodityFactory.create(Mango.class);
        mango.setName("芒果");
        mango.setPrice(new BigDecimal("20"));

        //购买
        List<Detail> detailList = new ArrayList<>();

        Detail appleDetail = new Detail(apple, 2);
        Detail strawberryDetail = new Detail(strawberry,2);
        Detail mangoDetail = new Detail(mango, 10);

        detailList.add(appleDetail);
        detailList.add(strawberryDetail);
        detailList.add(mangoDetail);

        //优惠劵
        Coupon coupon = new Coupon("满100减10元", new BigDecimal("100"), new BigDecimal("10"));
        List<Coupon> couponList = new ArrayList<>();
        couponList.add(coupon);

        SellService sellService = new SellServiceImpl();
        try {
            BigDecimal  amount = sellService.collectAmount(detailList ,couponList);
            System.out.println("合计收款：" + amount);
        }catch (Exception e){
            System.out.println("收钱程序异常");
        }
    }
}
